@layout BlogLayout
@page "/admin/blog/settings/"
@inject HttpClient _http
@inject IStringLocalizer<Resource> _localizer
@inject IToaster _toaster
@inject IJSRuntime JSRuntime

<PageTitle Title="@_localizer["blog-settings"]" />

@if (Blog != null)
{
    <h1 class="section-title">@_localizer["blog-settings"]</h1>
    <div class="section-content -half">
        <EditForm model="@Blog" OnValidSubmit="Save">
            <DataAnnotationsValidator />
            <ValidationSummary />
            <div class="form-item">
                <div class="form-check form-switch">
                    <input class="form-check-input" type="checkbox" @bind="Blog.IncludeFeatured" id="IncludeFeaturedSwitch">
                    <label class="form-check-label" for="IncludeFeaturedSwitch">@_localizer["include-featured"]</label>
                </div>
            </div>
            <div class="form-item">
                <label class="form-label">@_localizer["items-per-page"]</label>
                <input type="text" class="form-control" @bind="Blog.ItemsPerPage" name="pageitems" />
            </div>
            <div class="form-item">
                <button type="submit" class="btn btn-blogifier px-5">@_localizer["save"]</button>
            </div>
        </EditForm>
    </div>
}
<ToasterComponent @ref="Toaster" />

@code {
    protected Blog Blog { get; set; }
    protected ToasterComponent Toaster;

    protected override async Task OnInitializedAsync()
    {
        Blog = await _http.GetFromJsonAsync<Blog>("api/blog");
    }

    protected async Task Save()
    {
        Toaster.Toast(await _http.PutAsJsonAsync<Blog>("api/blog", Blog));
    }
}
